import tensorflow as tf
import keras
import matplotlib.pyplot as plt
from keras import layers, datasets
import numpy as np

print(keras.__version__)
(x_train, y_train), (x_test, y_test) = datasets.mnist.load_data()

print(tf.version.VERSION)

x_train = x_train.reshape(-1, 784) / 255.0
x_test = x_test.reshape(-1, 784) / 255.0

y_train = y_train.astype(np.float32)
y_test = y_test.astype(np.float32)

y_train = keras.utils.to_categorical(y_train, 10)
y_test = keras.utils.to_categorical(y_test, 10)
model = keras.Sequential()

# 第一层要多写一个参数，输入维度
model.add(layers.Dense(128, activation='selu', input_shape=(784, )))
# model.add(layers.AlphaDropout(0.1))
# model.add(layers.BatchNormalization())
# model.add(layers.Activation('relu'))
model.add(layers.Dense(64, activation='selu'))
# model.add(layers.AlphaDropout(0.1))
model.add(layers.Dense(10, activation='softmax'))

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=64, epochs=20, validation_data=(x_test, y_test))
model.summary()

